import { Widget, _decorator, Node, Label, Button } from 'cc';
import { UIBase } from '../scripts/scriptBase/UIBase';
import { UI } from '../scripts/enum/UI';
import { CfgLoginReward } from '../scripts/config/CfgLoginReward';
import { ArrayUtil } from '../scripts/util/ArrayUtil';
import { StorageUtil } from '../scripts/util/StorageUtil';
import { AdMgr } from '../scripts/manager/AdMgr';
import { PREVIEW } from 'cc/env';
const { ccclass, property, requireComponent } = _decorator;

@ccclass('sideNode/UiSideNode')
@requireComponent(Widget)
export class UiSideNode extends UIBase {

    @property(Label)
    public getRewardBtnLabel: Label = null;

    @property(Button)
    public getRewardBtn: Button = null;

    @property(Node)
    public openSideBtn: Node = null;

    protected onEnable(): void {
       this.onRefresh();
    }

    onRefresh(){
        AD_TouTiao.isSideEnter= localStorage.getItem("isSidEnter");
        
        this.getRewardBtnLabel.string = AD_TouTiao.isSideEnter?"领取奖励":"前往侧边栏";

        var isSidReward =  localStorage.getItem("isSidReward"); 
        if (isSidReward){
            this.getRewardBtnLabel.string = "奖励已领取";
            this.getRewardBtn.interactable = false;
            this.openSideBtn.active = false;
        }
    }

    public onOpen(data?: any): void {
        
    }

    public onClose(data?: any): void {

    }

    protected onBtnCloseClick(): void {
        this.node.active = false;
        //this.close()
    }

    protected onBtnGetAllClick(): void {
        if (PREVIEW){
            return
        }
        if (AD_TouTiao.isSideEnter){
            AD_TouTiao.freeAdNum = 3;
            localStorage.setItem("isSidReward", "true");
        }else{
            AD_TouTiao.navigateToScene();
        }
        this.onRefresh();
        // this.close()
        // this.open(UI.GetReward, CfgLoginReward)
        // StorageUtil.setItem('loginRewardGetTime', Date.now())
    }

    // protected onBtnGetOneClick(): void {
    //     AdMgr.showRewardedVideo(()=>{
    //         this.close()
    //         this.open(UI.GetReward, [ArrayUtil.pickItem(CfgLoginReward)])
    //         StorageUtil.setItem('loginRewardGetTime', Date.now())
    //     })
    // }

}


